<?php


namespace app\admin\controller;


use app\admin\model\ArchivesDeceasedModel;
use app\admin\model\CarveModel;
use app\admin\model\ChangeModel;
use app\admin\model\ContractModel;
use app\admin\model\CustomerInfoModel;
use app\admin\model\MaintenanceProjectModel;
use app\admin\model\OrderDepositModel;
use app\admin\model\OrderDepositSendModel;
use app\admin\model\OrderGoodsModel;
use app\admin\model\OrderModel;
use app\admin\model\OrderPayLogModel;
use app\admin\model\PayDepositModel;
use app\admin\model\ProtectPaymentModel;
use app\admin\model\RetreatTombModel;
use app\admin\model\ServiceBuriedModel;
use app\admin\model\ServiceDepositModel;
use app\admin\model\ServiceMoveModel;
use app\admin\model\ServiceWeibaoModel;
use app\admin\model\TombareaInformationProductModel;
use app\admin\model\TombareaRowColModel;
use cmf\controller\AdminBaseController;
use think\Db;

class FinanceController extends  AdminBaseController
{

    public function index($ajax=0){
        $data = $this->request->param();
        if ($ajax==1){
            $page = $this->request->get("page", 0);
            $limit = $this->request->get("limit", 10);
            $real_name = $this->request->get("real_name", '');
            $real_phone = $this->request->get("real_phone", '');
            $start_time = $this->request->get("start_time", '');
            $end_time = $this->request->get("end_time", '');
            $type = $this->request->get("type", '');
            $t = $this->request->get("t", 1);
            $model = Db::name('order_pay_log')->order('add_time desc')->where('is_delete',0) ;

            if ($t==2){
                $model = $model->where('status', 1);
            }else{
                $model = $model->where('status', 0);
            }

            if (!empty($type))
                $model->where('type', $type);

            if (!empty($real_name))
                $model->whereLike('real_name', $real_name);

            if (!empty($real_phone))
                $model->whereLike('real_phone', $real_phone);
            if (!empty($start_time)){
                $model->whereTime('add_time', '>=',  strtotime($start_time));
            }
            if (!empty($end_time)) {
                $model->whereTime('create_time', '<=', strtotime($end_time . '+1 day'));
            }
            $list = $model->limit($page,$limit)->select();
            $total =$model->count();
            $arr_list =[];
            foreach ($list as $k => &$val) {
                $val['handle_name'] = cmf_get_admin_name($val['handle']);
                $val['payrealname'] = cmf_get_admin_name($val['pay_real_name']);
                $val['pay_type_name'] = cart_type('pay',!empty($val['pay_type'])?$val['pay_type']:1);
                $val['add_time'] = date('Y-m-d H:i:s',$val['add_time']);
                if ($val['status']==1){
                    $val['add_time'] = date('Y-m-d H:i:s',$val['collect_time']);
                }
                $arr_list[] = $val;
            }
            $result = array("total" => $total, "rows" => $arr_list);
            return json($result);
        }
        $this->assign("results",[]);
//         页面传值
//        $page = $results->render();
        $this->assign("page", 0);

        return $this->fetch();
    }
    // 供货商成本结算
    public function supplier(){
        $real_name = $this->request->param("real_name", '');
        $real_phone = $this->request->param("real_phone", '');
        $start_time = $this->request->param("start_time", '');
        $end_time = $this->request->param("end_time", '');
        $supplier = $this->request->param("supplier", '');
        $diding = $this->request->param("diding", '');
        $model = Db::name('order_pay_log')->alias("op")
            ->field("op.*,u.user_nickname,t.reacher,p.tomb_region,p.tomb_num,c.buyer_name,c.buyer_phone,e.purchase_id,e.pact_name,e.purchase_id")
            ->join("dj_order o","o.order_id = op.order_id","left")
            ->join("dj_customer_info c","o.customer_id = c.id","left")
            ->join("dj_tombarea_row_col t","o.tomb_id = t.colID","left")
            ->join("dj_tombarea_information_product p","t.colID = p.tomb_id","left")
            ->join("dj_product d","d.id = p.new_pro","left")
            ->join("dj_purchase_product_order pp","pp.pro_id = d.id","left")
            ->join("dj_purchase e","e.purchase_id = pp.purchase_id","left")
            ->join("dj_user u","u.id = e.supplier","left")
            ->where('o.status',2)
            ->order('op.add_time desc')
            ->where('op.type',2)
            ->where('op.is_delete',0)
            ->where('op.status',1)
            ->where('e.supplier',">",0);
        if ($supplier){
            $model->where('e.supplier', $supplier);
        }
        if ($diding){
            $model->where('t.reacher', $diding);
        }
        if (!empty($real_name))
            $model->whereLike('c.buyer_name', "%".$real_name."%");

        if (!empty($real_phone))
            $model->whereLike('c.buyer_phone', "%".$real_phone."%");

        if (!empty($start_time)){
            $model->whereTime('op.add_time', '>=',  strtotime($start_time));
        }
        if (!empty($end_time)) {
            $model->whereTime('op.add_time', '<=', strtotime($end_time . '+1 day'));
        }
        $list = $model->paginate(15);
//dump( Db::name('order_pay_log')->getLastSql());exit();
        foreach ($list as $k => &$val) {
            $val['handle_name'] = cmf_get_admin_name($val['handle']);
            $val['add_time'] = date('Y-m-d H:i:s',$val['add_time']);
            if ($val['status']==1){
                $val['add_time'] = date('Y-m-d H:i:s',$val['collect_time']);
            }
        }

        $this->assign("results",$list);

        // 供货商
        $suppliers = dept_per(5);
        $this->assign("suppliers", $suppliers);
        $this->assign("supplier", $supplier);
        $this->assign("diding", $diding);
        // 抵顶人
        $didings = dept_per(7);
        $this->assign("didings", $didings);
        $page = $list->render();
        $this->assign("page", $page);

        return $this->fetch();
    }
    // 业务 退墓 和 退款
    public function refund($ajax=0){
        $data = $this->request->param();
        if ($ajax==1){
            $page = $this->request->get("page", 0);
            $limit = $this->request->get("limit", 10);
            $real_name = $this->request->get("real_name", '');
            $real_phone = $this->request->get("real_phone", '');
            $start_time = $this->request->get("start_time", '');
            $end_time = $this->request->get("end_time", '');
            $type = $this->request->get("type", '');
            $t = $this->request->get("t", 1);
            $model = Db::name('pay_refund')->alias('pr')
                ->field('pr.*,pl.deal_price,pl.pay_sn')
                ->join('dj_order_pay_log pl','pr.pay_id = pl.id')
                ->order('pr.add_time desc') ;
            $model  = $model->where('pl.is_delete',0);

            if ($t==1){
                $model = $model->where('pr.refund_state', '<',2);
            }elseif ($t==2){
                $model = $model->where('pr.refund_state',2)->where('pr.refund_apply_state',2);
            }

            if (!empty($type))
                $model->where('pt.type', $type);
            if (!empty($real_name))
                $model = $model->whereLike('pr.real_name', $real_name);

            if (!empty($real_phone))
                $model = $model->whereLike('pr.real_phone', $real_phone);
            if (!empty($start_time)){
                $model = $model->whereTime('pr.add_time', '>=',  strtotime($start_time));
            }
            if (!empty($end_time)) {
                $model = $model->whereTime('pr.add_time', '<=', strtotime($end_time . '+1 day'));
            }
            $list = $model->limit($page,$limit)->select();
            $total =$model->count();
            $arr_list =[];
            foreach ($list as $k => &$val) {
                if ($val['type']==1){
                   $info =  PayDepositModel::where(['refund_id'=>$val['id']])->find();
                   $val['handle_user'] = cmf_get_admin_name($info['handle']);
                    $val['mw_num'] = $info['mw_num'];
                }else{
                   $info =  RetreatTombModel::where(['refund_id'=>$val['id']])->find();
                    $val['mw_num'] = $info['mw_num'];
                    $val['handle_user'] = $info['handle_user'];
                }
                $val['add_user_name'] = cmf_get_admin_name($val['add_user']);
                $val['refund_user_name'] = cmf_get_admin_name($val['refund_user']);
                $val['refund_type_name'] = cart_type('pay',$val['refund_type']);
                $val['refund_time'] = date('Y-m-d H:i:s',$val['refund_time']);
                $val['add_time'] = date('Y-m-d H:i:s',$val['add_time']);
                $arr_list[] = $val;
            }
            $result = array("total" => $total, "rows" => $arr_list);
            return json($result);
        }
        return $this->fetch();
    }
    // 寄存 收款
    public function pay_jcjs(){
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $pay_id = $param['pid'];
            $order_id = $param['order_id'];
            $customer_id = $param['customer_id'];
            $tomb_id = $param['tomb_id'];
            $otype = $param['dtype']; // 1保存2打印结算单3退款4打证
            switch ($otype) {
                case 'js':
                    $pay_update = [
                        'real_name'=>$param['rn'],//付款人
                        'real_phone'=>$param['rh'],//付款人
                        'pay_type'=>$param['pt'],//付款方式
                        'remark'=>$param['rk'],//备注
                        'pay_real_name'=>cmf_get_current_admin_id(),
                        'collect_time'=>time(),
                        'status'=>1,
                    ];
                    if (!empty($data['discount_price'])){
                        $pay_ins['free_price']=$data['selling_price']*$data['discount_price'];
                    }
                    Db::name('order_pay_log')->where(['id'=>$pay_id])->update($pay_update);
                    Db::name('order')->where(['order_id'=>$param['order_id']])->update(['status'=>2]);
                    OrderDepositModel::update(['pay_status'=>1],['pay_id'=>$pay_id]);

                    return json(['code'=>0,'msg'=>'结算成功','data'=>['mwid'=>$param['tomb_id'],'oid'=>$param['order_id'],'cid'=>$customer_id,'pid'=>$pay_id]]);
                    break;
                case 'rt':
                    $pay_model = new OrderPayLogModel();
                    $res = $pay_model->doRefreshUpdataDelete($pay_id);
                    if ($res){
                        return $this->success('重置成功。提示：数据无法恢复',url('index'));
                    }else{
                        return $this->error($pay_model->getError());
                    }
                    break;
            }
        }

        $data = $this->request->param();
        $order_id =  $data['order_id'];

        $pay_id = $data['pay_id'];
        $result_order = Db::name('order')->alias('o')->field('o.*,p.*,c.reacher')
            ->join("dj_tombarea_row_col c","o.tomb_id = c.colID")
            ->join("dj_tombarea_information_product p","o.tomb_product_id = p.id","left")
            ->where(['o.order_id'=>$order_id])->find();

        $result_order['tomb_regulation'] = $this->regulation_arr[$result_order['tomb_regulation']];
        $result_order['pro_status'] = $this->col_status[$result_order['pro_status']];
        $result_order['add_time'] = date('',$result_order['add_time']);//$result_order['pro_status']];
        $result_order['tomb_type'] = $this->cate_arr[$result_order['tomb_type']];

        $result_customer = Db::name('customer_info')->where('id',$result_order['customer_id'])->find();
//        $result_deposit = Db::name('pay_deposit')->where('order_id',$order_id)->select();
        $order_deposit = Db::name('order_deposit')->where('customer_id',$result_order['customer_id'])->select();
        $order_deposit_info = Db::name('order_deposit')->where(['pay_id'=>$pay_id])->find();


        $result_order['discount_price']  = intval($result_order['discount_price']);
        $result_order['shoppingguide_name']  = cmf_get_admin_name($result_order['shoppingguide']);
        $result_order['agent_user_name']  = cmf_get_admin_name($result_order['agent_user']);
        $result_order['handle_name']  = cmf_get_admin_name($result_order['handle']);
        $result_order['payaddtime']  = date('Y-m-d H:i:s',time());
        $pay_info = Db::name('order_pay_log')->where(['id'=>$pay_id])->find();
        $result_customer['cart_type'] = cart_type('cart',$result_customer['cart_type']) ;// ==1?'身份证': $result_customer['cart_type']==2?'护照':'';
        $this->assign([
            'pay_info'=>$pay_info,
            'result'=>$result_order,
            'customer'=>$result_customer,
            'deposit'=>[],
            'order_id'=>$order_id,
            'order_deposit_info'=>$order_deposit_info,
        ]);
        return $this->fetch();
    }

    //结算
    public function orderPay(){
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $pay_id = $param['pay_id'];
            $order_id = $param['order_id'];
            $customer_id = $param['customer_id'];

            $order_pay_info = OrderPayLogModel::where(['id'=>$pay_id])->find();
            $order_info = OrderModel::where(['order_id'=>$param['order_id']])->find();
            if ($param['dtype']=='js'){
                $pay_update = [
                    'discount_rate'=>$param['discount_rate'],//折扣
                    'deal_price'=>$param['deal_price'],//成交
                    'deposit_price'=>$param['deposit_price'],//定金
                    'total_price'=>$param['total_price'],//应收金额
                    'goods_price'=>$param['goods_price'],//商品金额
                    'real_name'=>$param['real_name'],//付款人
                    'real_phone'=>$param['real_phone'],//付款人
                    'pay_type'=>$param['pay_type'],//付款方式
                    'remark'=>$param['remark'],//备注
                    'pay_real_name'=>cmf_get_current_admin_id(),
                    'collect_time'=>time(),
                    'status'=>1,
                ];
                if ($order_pay_info['status']==0){
                    Db::name('order_pay_log')->where(['id'=>$pay_id])->update($pay_update);
                    OrderModel::update(['status'=>2],['order_id'=>$order_id]);
                    if (!empty($order_info['orders_id'])){
                        Db::name('orders')->where(['id'=>$order_info['orders_id']])->update(['order_status'=>3,'status'=>1,'order_id'=>$order_id]);
                    }
                    PayDepositModel::update(['status'=>2],['order_id'=>$order_id]);
                    TombareaRowColModel::update(['col_status'=>5],['colID'=>$param['tomb_id']]);

                    return json(['code'=>0,'msg'=>'结算成功','data'=>['mwid'=>$param['tomb_id'],'oid'=>$param['order_id'],'cid'=>$customer_id,'pid'=>$pay_id]]);
                }else{
                    return json(['code'=>1,'msg'=>'已结算']);
                }
            }elseif ($param['dtype']=='rt'){

                $tomb_id     = $param['tomb_id'];
                $tomb_num = $param['tomb_num'];
                $order_id    = $param['order_id'];
                $pay_id      = $param['pay_id'];
                $customer_id = $param['customer_id'];
                $pd_pl_where=[
                    'pl.type'=>1,
                    'pl.order_id'=>$order_id,
                    'pl.customer_id'=>$customer_id,
                    'pl.tomb_id'=>$tomb_id,
                    'pl.status'=>1,
                    'pl.refund_state'=>0,
                    'pd.order_id'=>$order_id,
                    'pd.customer_id'=>$customer_id,
                    'pd.mw_id'=>$tomb_id,
                    'pd.dtype'=>1,
                    'pd.status'=>1,
                    'pd.refund_state'=>0
                ];

                $result_deposit = Db::name('pay_deposit')->alias('pd')
                    ->field('pl.pay_sn,pl.real_name,pl.add_time,pl.deposit_price,pl.pay_type,pl.pay_real_name,pd.status,pl.type')
                    ->join('dj_order_pay_log pl','pd.pay_id = pl.id')
                    ->where($pd_pl_where)
                    ->select();

                if ($result_deposit){
                    return $this->error('很抱歉，当前墓位下有定金信息，无法重置当前墓位信息');
                }else{
                    OrderModel::where(['order_id'=>$order_id])->delete();
                    OrderGoodsModel::where(['order_id'=>$order_id])->delete();
                    CustomerInfoModel::where(['id'=>$customer_id])->delete();
                    OrderPayLogModel::where(['id'=>$pay_id])->delete();
                    PayDepositModel::where(['mw_id'=>$tomb_id])->delete();
                    TombareaRowColModel::update(['col_status'=>1],['colID'=>$tomb_id]);
                    deldir('upload/archives/'.$tomb_num);//清空文件
                    return $this->success('重置成功。提示：数据无法恢复');
                }
            }elseif ($param['dtype']==2){
                $pay_update = [
                    'discount_rate'=>$param['discount_rate'],//折扣
                    'deal_price'=>$param['deal_price'],//成交
                    'deposit_price'=>$param['deposit_price'],//定金
                    'goods_price'=>$param['goods_price'],//商品金额
                    'total_price'=>$param['total_price'],//应收金额
                    'real_name'=>$param['real_name'],//付款人
                    'real_phone'=>$param['real_phone'],//付款人
                    'pay_type'=>$param['pay_type'],//付款方式
                    'remark'=>$param['remark'],//备注
                    'pay_real_name'=>cmf_get_current_admin_id(),
                    'collect_time'=>time(),
                    'status'=>1,
                ];

                Db::name('order_pay_log')->where(['id'=>$pay_id])->update($pay_update);
                Db::name('order')->where(['order_id'=>$param['order_id']])->update(['status'=>2]);
                PayDepositModel::update(['finish_time'=>time(),'status'=>2],['id'=>$param['deposit_id']]);

                return json(['code'=>1,'msg'=>'结算成功','data'=>['mwid'=>$param['tomb_id'],'oid'=>$param['order_id'],'cid'=>$customer_id],'url'=>url('PrintSettlement').'?order_id='.$param['order_id'].'&pay_id='.$pay_id]);
            }
        }
        $data = $this->request->param();
        $order_id =  $data['order_id'];
        $pay_id =  $data['pay_id'];

        $result_order = Db::name('order')->alias('o')->field('o.*,p.*,c.reacher')
            ->join("dj_tombarea_row_col c","o.tomb_id = c.colID")
            ->join("dj_tombarea_information_product p","o.tomb_product_id = p.id","left")
            ->where(['o.order_id'=>$order_id])->find();

        if (empty($result_order)){
            return $this->error('数据已清空');
        }

        $result_order['tomb_regulation'] = $this->regulation_arr[$result_order['tomb_regulation']];
        $result_order['pro_status'] = $this->col_status[$result_order['pro_status']];
        $result_order['add_time'] = date('',$result_order['add_time']);//$result_order['pro_status']];
        $result_order['tomb_type_name'] = $this->cate_arr[$result_order['tomb_type']];

        $result_customer = Db::name('customer_info')->where('id',$result_order['customer_id'])->find();
        $result_deposit = Db::name('pay_deposit')->where('order_id',$order_id)->select();
        $deposit_price=0;
        $deposit_id='';
        foreach ($result_deposit as $kdep=>&$vdep){
            if ($deposit_id){
                $deposit_id=$deposit_id.','.$vdep['id'];
            }else{
                $deposit_id=$vdep['id'];
            }
            $deposit_price+=$vdep['deposit_price'];
        }


        $result_goods = Db::name('order_goods')->where('order_id',$order_id)->select();
        $goods=[];
        $goods_total_price=0;
        foreach ($result_goods as $k=>&$valg){
                $cate_name = Db::name('goods')->alias('g')->field('c.cate_name')
                    ->join('dj_cate c','c.id = g.cate_p_id','left')
                    ->where('g.id',$valg['goods_id'])->find();
                $info['goods_id'] = $valg['goods_id'];
                $info['goods_name'] = $valg['goods_name'];
                $info['goods_price'] = $valg['goods_price'];
                $info['num'] = $valg['num'];
                $info['cate_name'] = $cate_name['cate_name'];
                $info['discount_price'] = $valg['discount_price']!=0?1-$valg['discount_price']."% ":0;
                $info['total_price'] = $valg['num']*$valg['goods_price'];
                $info['add_user'] = $valg['add_user'];
                $goods[] = $info;
                $goods_total_price+=$info['total_price'];
        }

        $pay_info = Db::name('order_pay_log')->where(['id'=>$pay_id])->find();

        $pay_info['deposit_id']  = $deposit_id;
        $result_order['discount_price']  = intval($deposit_price);
        $result_order['shoppingguide_name']  = cmf_get_admin_name($result_order['shoppingguide']);
        $result_order['agent_user_name']  = cmf_get_admin_name($result_order['agent_user']);
        $result_order['handle_name']  = cmf_get_admin_name($result_order['handle']);
        $result_order['payaddtime']  = date('Y-m-d H:i:s',$result_order['sign_time']);
        $this->assign([
            'pay_info'=>$pay_info,
            'result'=>$result_order,
            'customer'=>$result_customer,
            'deposit'=>$result_deposit,
            'goods_arr'=>$goods,
            'order_id'=>$order_id,
            'goods_total_price'=>$goods_total_price,
        ]);


        if ($result_order['tomb_type']==1){
            return $this->fetch('orderpay_goods');
        }elseif ($result_order['tomb_type']==2){
            return $this->fetch('orderpay_arl');
        }elseif ($result_order['tomb_type']==3){
            return $this->fetch('orderpay_ecological');
        }elseif ($result_order['tomb_type']==4){
            return $this->fetch('orderpay_goods');
        }

        return $this->fetch();
    }
    /**
     * 财务管理收费
     */
    public function shoufei_ajax(){
        if ($this->request->isPost()) {
            $data = $this->request->param();
            $yulan = $this->request->param('yl',0);
            $pay_id = $data['pid'];

            $pay_info = OrderPayLogModel::where(['id' => $pay_id])->find();

            $other_id = $pay_info['other_id'];
            $order_id = $pay_info['order_id'];
            $mw_id = $pay_info['tomb_id'];
            $type = $pay_info['type'];
            $itype = $pay_info['itype'];
            $customer_id = $pay_info['customer_id'];
            $pay_real_name = cmf_get_admin_name($pay_info['pay_real_name']);//收费人员

            $josn_array['code'] =0;
            $josn_array['msg'] ='支付成功，请打印单据';
            $josn_array['head_title'] ='服务结算单';
            $josn_array['operate_name'] ='服务费用（售后服务的收费项目）';
            $josn_array['type'] = $pay_info['type'];
            $josn_array['itype'] = $pay_info['itype'];;

            // 单据
            $danju_url = url('Print/print_cert');
            if ($yulan == 0) {
                if ($pay_info['status']==0) {
                    if ($pay_info)
//                $danju_url = url('Print/print_cert');
                        if (empty($data['rn'])) return json(['code' => 1, 'msg' => '请输入付款人姓名！']);
                    if (empty($data['rh'])) return json(['code' => 1, 'msg' => '请输入付款人手机号！']);

                    $pay_update = [
                        'real_name' => $data['rn'],//付款人
                        'real_phone' => $data['rh'],//付款人手机号
                        'pay_type' => $data['pt'],//付款方式
                        'remark' => $data['rk'],//备注
                        'pay_real_name' => cmf_get_current_admin_id(),
                        'collect_time' => time(),
                        'status' => 1,
                    ];
                    OrderPayLogModel::update($pay_update, ['id' => $pay_id]);

                    if ($pay_info['type'] == 1) {
                        // 定金
                        if ($pay_info['itype'] == 1) {
                            $dj_info = PayDepositModel::where(['id' => $pay_info['other_id']])->find();
                            OrderPayLogModel::update(['status' => 4], ['id' => $pay_id]);
                            TombareaRowColModel::update(['col_status' => 1], ['colID' => $pay_info['tomb_id']]);
                            PayDepositModel::update(['status' => 4], ['id' => $pay_info['other_id']]);
                            OrderModel::update(['deposit_price' => $pay_info['deposit_price'], 'status' => 3], ['order_id' => $order_id]);
                            if ($dj_info['orders_id'] != 0) {
                                Db::name('orders')->where(['id' => $dj_info['orders_id']])->update(['status' => 1, 'order_id' => $order_id]);
                            }
                        } else {
                            $dj_info = PayDepositModel::where(['id' => $pay_info['other_id']])->find();
                            // 定金
                            TombareaRowColModel::update(['col_status' => 3], ['colID' => $pay_info['tomb_id']]);
                            PayDepositModel::update(['status' => 1, 'finish_time' => time(), 'pay_time' => time()], ['id' => $pay_info['other_id']]);
                            OrderPayLogModel::update(['status' => 1], ['id' => $pay_id]);
                            OrderModel::update(['deposit_price' => $pay_info['deposit_price']], ['order_id' => $order_id]);
                            if ($dj_info['orders_id'] != 0) {
                                Db::name('orders')->where(['id' => $dj_info['orders_id']])->update(['status' => 1, 'order_id' => $order_id]);
                            }
                        }
                        // 定金
                        $danju_url = $danju_url . "?type=1&pay_id={$pay_id}";
                        return json(['danju_url' => $danju_url, 'code' => 0, 'msg' => '结算成功', 'type' => 1, 'itype' => 0]);
                    } elseif ($pay_info['type'] == 2) {
                        if ($pay_info['itype'] == 0) {
                            //购买

                        } elseif ($pay_info['itype'] == 1) {
                            // 寄存
                            $josn_array['head_title'] = '寄存收据';
                            $danju_url = $danju_url . "?type=2&pay_id={$pay_id}";
                            if (!empty($data['discount_price'])) {
                                $pay_ins['free_price'] = $data['selling_price'] * $data['discount_price'];
                            }
                            OrderModel::update(['status' => 0], ['order_id' => $order_id]);
                            ServiceDepositModel::update(['submit_status' => 2], ['pay_id' => $pay_id]);
                            OrderDepositModel::update(['pay_status' => 1], ['pay_id' => $pay_id]);

                            TombareaRowColModel::update(['col_status' => 5], ['colID' => $mw_id]);
                            $josn_array['mz'] = CustomerInfoModel::getmuzheng($customer_id);
                        }

                    } elseif ($pay_info['type'] == 3) {
                        //2维保3落葬业务4维护费5寄存续费6墓碑刻制7挂失证件工本费 11 12-
                        switch ($pay_info['itype']) {
                            case 2:
                                $josn_array['head_title'] = '维保结算单';
                                ServiceWeibaoModel::update(['pay_status' => 1, 'pay_id' => $pay_id], ['id' => $other_id]);
                                $danju_url = $danju_url . "?type=3&pay_id={$pay_id}";
                                break;
                            case 3:
                                $josn_array['head_title'] = '服务结算单';
                                ServiceBuriedModel::update(['pay_status' => 1], ['id' => $other_id, 'pay_id' => $pay_id]);
                                OrderGoodsModel::update(['mw_id' => $mw_id, 'pay_id' => $pay_id], ['buried_id' => $other_id]);
                                $danju_url = $danju_url . "?type=3&pay_id={$pay_id}";

                                $head_top = $this->getBuriedInfo($customer_id, $other_id);
                                $head_top['pay_name'] = $pay_real_name;
                                break;
                            case 4:
                                $josn_array['head_title'] = '服务结算单';
                                $pp_info = ProtectPaymentModel::where(['id' => $other_id])->find();
                                $order_info = OrderModel::where(['order_id' => $pp_info['order_id']])->find();
                                $order_id = $pp_info['order_id'];

                                if ($order_info['whq_end_date'] < time()) {
                                    $whq_end_date = unixtime_to_date_inc(time(), intval($pp_info['duration']));
                                    OrderModel::update(['whq_end_date' => $whq_end_date], ['order_id' => $order_id]);
                                } else {
                                    $whq_end_date = unixtime_to_date_inc(intval($order_info['whq_end_date']), intval($pp_info['duration']));
                                    OrderModel::update(['whq_end_date' => $whq_end_date], ['order_id' => $order_id]);

                                }
                                ProtectPaymentModel::update(['pay_status' => 1, 'pay_time' => time(), 'pay_user' => cmf_get_admin_name(), 'end_time' => $whq_end_date,
                                    'pay_id' => $pay_id], ['id' => $other_id]);
                                $danju_url = $danju_url . "?type=3&pay_id={$pay_id}";
                                break;
                            case 5:
                                $josn_array['head_title'] = '寄存收据';
                                $depdend_info = OrderDepositSendModel::where(['id' => $other_id])->find();
                                $dep_info = OrderDepositModel::where(['id' => $depdend_info['deposit_id']])->find();
                                //修改时间
                                if (time() < $dep_info['deposit_end_time']) {
                                    $deposit_end_time = unixtime_to_date_inc($dep_info['deposit_end_time'], intval($depdend_info['storage_time']));
                                } else {
                                    $deposit_end_time = unixtime_to_date_inc(time(), intval($depdend_info['storage_time']));;
                                }
                                $storage_time_c = $dep_info['storage_time'] + intval($depdend_info['storage_time']);
                                OrderDepositModel::update(['storage_time' => $storage_time_c, 'deposit_end_time' => $deposit_end_time], ['id' => $depdend_info['deposit_id']]);

                                $danju_url = $danju_url . "?type=3&id={$other_id}&order_id={$order_id}&pay_id={$pay_id}";
                                break;
                            case 6:
                                $josn_array['head_title'] = '服务结算单';
                                CarveModel::update(['pay_status' => 2, 'pay_id' => $pay_id], ['id' => $other_id]);
                                $danju_url = $danju_url . "?type=3&id={$other_id}&order_id={$order_id}&pay_id={$pay_id}";
                                break;
                            case 7:
                                $josn_array['head_title'] = 'log_list';
                                ChangeModel::update(['pay_status' => 2, 'pay_id' => $pay_id], ['id' => $other_id]);
                                $danju_url = $danju_url . "?type=3&id={$other_id}&order_id={$order_id}&pay_id={$pay_id}";
                                break;
                            case 8:
                                $josn_array['head_title'] = '服务结算单';
                                ServiceMoveModel::update(['pay_status' => 1, 'pay_id' => $pay_id], ['id' => $other_id]);
                                $danju_url = $danju_url . "?type=3&id={$other_id}&id={$other_id}&pay_id={$pay_id}";
//                            return json(['code' => 0, 'msg' => '支付成功，请打印单据', 'danju_url' => $danju_url,'type'=>3,'itype'=>$pay_info['itype']]);
                                break;
                            case 11:
                                $josn_array['head_title'] = '维保结算单';
                                ServiceWeibaoModel::update(['pay_status' => 1, 'pay_id' => $pay_id], ['id' => $other_id]);
                                $danju_url = $danju_url . "?type=3&pay_id={$pay_id}";
                                break;
                            case 12:
                                $josn_array['head_title'] = '维保结算单';
                                ServiceWeibaoModel::update(['pay_status' => 1, 'pay_id' => $pay_id], ['id' => $other_id]);
                                $danju_url = $danju_url . "?type=3&pay_id={$pay_id}";
                                break;
                        }
                    } elseif ($pay_info['type'] == 4) {
                        $danju_url = $danju_url . "?type=4&pay_id={$pay_id}";
                        $josn_array['head_title'] = '销售商品结算单';
                    }
                    $josn_array['danju_url'] = $danju_url;
                }else{
                    $josn_array['code'] =1;
                    $josn_array['msg'] ='已结算';
                }
                return json($josn_array);
            }else {
                $danju_url = url('Print/print_cert');
                // 预览单据 url
                if ($pay_info['type'] == 1) {
                    // 定金
                    $danju_url = $danju_url."?type=1&pay_id={$pay_id}";
                    return json(['danju_url'=>$danju_url,'code'=>0,'msg'=>'结算成功']);
                } elseif ($pay_info['type'] == 2) {
                } elseif ($pay_info['type'] == 3) {
                    //2维保3落葬业务4维护费5寄存续费6墓碑刻制7挂失证件工本费 8迁墓
                    $operate_name = '服务结算单';
                    switch ($pay_info['itype']) {
                        case 0:
                            break;
                        case 1:
                            // 定金
                            $danju_url = $danju_url."?type=2&order_id={$order_id}&pay_id={$pay_id}";
                            break;
                        case 2:
                            // 维保
                            $danju_url = $danju_url."?type=3&id={$other_id}&order_id={$order_id}&pay_id={$pay_id}";
                            break;
                        case 3:
                            // 落葬业务
                            $danju_url = $danju_url."?type=3&pay_id={$pay_id}";
                            break;
                        case 4:
                            // 维护费业务
                            $danju_url = $danju_url."?type=3&pay_id={$pay_id}";
                            break;
                        case 5:
                            // 寄存续费
                            $danju_url = $danju_url."?type=3&pay_id={$pay_id}";
                            break;
                        case 6:
                            //墓碑刻制
                            $danju_url = $danju_url."?type=3&pay_id={$pay_id}";
                            break;
                        case 7:
                            //挂失证件工本费
                            $danju_url = $danju_url."?type=3&pay_id={$pay_id}";
                            break;
                        case 8:
                            // 迁墓
                            $danju_url = $danju_url."?type=3&pay_id={$pay_id}";
                            break;
                        case 9:
                            break;
                        case 10:
                            break;
                        case 11:
                            // 维保 - 换碑
                            $danju_url = $danju_url."?type=3&pay_id={$pay_id}";
                            return json(['danju_url'=>$danju_url,'code'=>0,'msg'=>'结算成功','type'=>3,'itype'=>11]);
                            break;
                        case 12:
                            // 维保 - 石材
                            $danju_url = $danju_url."?type=3&pay_id={$pay_id}";
                            break;
                    }
                    return json(['danju_url'=>$danju_url,'code'=>0,'msg'=>'结算成功','operate_name'=>$operate_name,''=>'','type'=>3,'itype'=>$pay_info['itype']]);
                } elseif ($pay_info['type'] == 4) {
                    //  商品
                    $danju_url = $danju_url."?type=4&pay_id={$pay_id}";
                }

                $josn_array['danju_url'] = $danju_url;
                return json($josn_array);
            }
        }else {
            $data = $this->request->param();
            $menu = $this->request->param('menu',0);
            $order_id = $data['order_id'];
            $pay_id = $data['pay_id'];
            $orderModel = new  OrderModel();
            $pay_info = OrderPayLogModel::where(['id' => $pay_id])->find();
            $other_id = $pay_info['other_id'];
            $customer_id = $pay_info['customer_id'];

            $field='ci.buyer_name,ci.buyer_phone,o.tomb_num,o.tomb_type,o.customer_id';
            $result =  Db::name('order')->alias('o')->field($field)
                ->join("dj_customer_info ci","o.customer_id = ci.id")
                ->join("dj_tombarea_information_product p","o.tomb_product_id = p.id")
                ->where("o.customer_id = '{$customer_id}' ")->find();

            $result_customer = Db::name('customer_info')->where('id', $customer_id)->find();
            $result_deposit = Db::name('order_pay_log')->where(['order_id' => $order_id, 'type' => 1])->select();
            $html = '';
            $danju_url = url();
            if ($pay_info['type'] == 1) {
                // 定金
                $pay_info['remark']= '';
                if ($result['tomb_type']==2){
                    if ($pay_info['itype']==1){
                        $html = "<p fid='1'>应退<mark class='red' >" . $pay_info['refund_price'] . "</mark>元，款项类型：退预付款</p>";
                        $pay_info['remark']= '退款方式：'.cart_type('cart',$pay_info['pay_type']).'。退款账号：'.$pay_info['refund_account'];
                    }else{
                        $html = "<p fid='1'>应交<mark >" . $pay_info['deposit_price'] . "</mark>元，款项类型：预付款</p>";
                    }
                }else{
                    if ($pay_info['itype']==1){
                        $html = "<p fid='1'>应退<mark class='red' >" . $pay_info['refund_price'] . "</mark>元，款项类型：退定金</p>";
                        $pay_info['remark']= '退款方式：'.cart_type('cart',$pay_info['pay_type']).'。退款账号：'.$pay_info['refund_account'];
                    }else{
                        $html = "<p fid='1'>应交<mark >" . $pay_info['deposit_price'] . "</mark>元，款项类型：定金</p>";
                    }
                }
                $danju_url = url();//单据
            } elseif ($pay_info['type'] == 2) {
            } elseif ($pay_info['type'] == 3) {
                //2维保3落葬业务4维护费5寄存续费6墓碑刻制7挂失证件工本费
                switch ($pay_info['itype']) {
                    case 0:
                        break;
                    case 1:
                        order_OrderModel::where(['order_id'=>$order_id])->find();
                        if ($result['tomb_type']==2){
                            $html = "<p fid='1'>应交<mark >" . $pay_info['deposit_price'] . "</mark>元，款项类型：预付款</p>";
                        }else{
                            $html = "<p fid='1'>应交<mark >" . $pay_info['deposit_price'] . "</mark>元，款项类型：定金</p>";
                        }
                        break;
                    case 2:
                        $array = MaintenanceProjectModel::where(['wb_id' => $other_id])->select();
                        foreach ($array as $key => &$value) {
                            if ($value['warranty_type'] == 1) {
                                $warranty_type = '维修';
                            } else {
                                $warranty_type = '换新';
                            }
                            $html .= "<p fid='1'>应交<mark >" . $value['total_price'] . "</mark>元，款项类型：" . $warranty_type . "：" . $value['part_name'] . "</p>";
                        }
                        $danju_url = url();
                        break;
                    case 3:
                        $array = Db::name('pay_project')->where(['buried_id' => $other_id, 'order_id' => $order_id])->select();
                        foreach ($array as $key => &$value) {
                            $html .= "<p fid='1'>应交<mark >" . $value['total_price'] . "</mark>元，款项类型：" . $value['project_type'] . " -" . $value['project_name'] . "</p>";
                        }
                        $danju_url = url();
                        break;
                    case 4:

                        $html = "<p fid='1'>应交<mark >" . $pay_info['total_price'] . "</mark>元，款项类型：维护费业务</p>";

                        $danju_url = url();
                        break;
                    case 5:
                        $html = "<p fid='1'>总价<mark class='ys' >" . $pay_info['total_price'] . "</mark>元，
                                减免 " . $pay_info['free_price'] . " 元，
                                实际收费<mark > " . $pay_info['actual_amount'] . " </mark>元，
                                  款项类型：寄存续费</p>";
                        break;
                    case 6:

                        $carve_info = Db::name('carve')->where(['id' => $other_id])->find();
                        $carves = explode(',',isset($carve_info['type'])?trim($carve_info['type']):'');
                        foreach ($carves as $key => $val){
                            if($val == 'image'){
                                $carve_title = '瓷像制作';
                                $carve_child = Db::name('carve_image')->where(['carve_id'=>$carve_info['id']])->select()->toArray();

                                $carve_shape = $carve_child[0]['shape'] == 1?"矩形":"椭圆形";
                                $html .= "<div class='form-group'>";
                                $html .= "<p><mark1>" . $carve_title . "</mark1>&nbsp;交付日期：" .  date('Y-m-d',$carve_child[0]['pay_time']) . " 价格：" . $carve_child[0]['price'];

                                $html .= " 形状：" . $carve_shape . " 规格：" . $carve_child[0]['specificat'] . "时</p>";
                                $html .= "</div>";
                            }elseif ($val == 'gold'){
                                $carve_child = Db::name('carve_gold')->where(['carve_id'=>$carve_info['id']])->select()->toArray();
                                $carve_title = '字体贴金';
                                $carve_c = $carve_child[0]['type'] == 1?"字体贴金":"描金漆";
                                $carve_unit = $carve_child[0]['unit'] == 1?"平方米":"套";

                                $html .= "<div class='form-group'>";
                                $html .= "<p><mark1>" . $carve_title . "</mark1> &nbsp;交付日期：" . date('Y-m-d',$carve_child[0]['pay_time']) . " 价格：" . $carve_child[0]['price'];

                                $html .= " 内容：" . $carve_c . " 单价：" . $carve_child[0]['unitprice'] . "/".$carve_unit."</p>";
                                $html .= "</div>";
                            }else{

                                $carve_child = Db::name('carve_insc')->where(['carve_id'=>$carve_info['id']])->select()->toArray();

                                //项目
                                $carve_title = '碑文刻制';
                                // 碑文状态
                                $carve_type = $carve_child[0]['type'] == 1 ?"首刻":$carve_child[0]['type'] == 2 ?"补刻":"重刻";
                                // 内容
                                $position = explode(',',isset($carve_child[0]['position'])?trim($carve_child[0]['position']):'');

                                foreach ($position as $k => $v){
                                    $position[$k] = $v == 1?"正面":$v == 2?"背面":$v == 3?"盖板":"局部";
                                }
                                $html .= "<div class='form-group'>";
                                $html .= "<p><mark1>" . $carve_title . "</mark1> &nbsp;交付日期：" .  date('Y-m-d',$carve_child[0]['pay_time']) . " 价格：" . $carve_child[0]['price'];

                                $html .= " 碑文状态：" . $carve_type . " 内容：" . implode(",",$position) . "</p>";
                                $html .= "</div>";
                            }
                        }
                        $html .= "<p fid='1'>应交<mark >" . $pay_info['total_price'] . "</mark>元，款项类型：墓碑刻制</p>";

                        break;
                    case 7:
                        $html = "<p fid='1'>应交<mark >" . $pay_info['total_price'] . "</mark>元，款项类型：挂失证件工本费</p>";
                        break;
                    case 8:
                        $html = "<p fid='1'>应交<mark >" . $pay_info['total_price'] . "</mark>元，款项类型：迁墓</p>";
                        break;
                    case 10:
                        break;
                    case 11:
                        $array = MaintenanceProjectModel::where(['wb_id' => $other_id])->select();
                        foreach ($array as $key => &$value) {
                            if ($value['warranty_type'] == 1) {
                                $warranty_type = '维修';
                            } else {
                                $warranty_type = '换新';
                            }
                            $html .= "<p fid='1'>应交<mark >" . $value['total_price'] . "</mark>元，款项类型：" . $warranty_type . "：" . $value['part_name'] . "</p>";
                        }
                        break;
                    case 12:
                        $array = MaintenanceProjectModel::where(['wb_id' => $other_id])->select();
                        foreach ($array as $key => &$value) {
                            if ($value['warranty_type'] == 1) {
                                $warranty_type = '维修';
                            } else {
                                $warranty_type = '换新';
                            }
                            $html .= "<p fid='1'>应交<mark >" . $value['total_price'] . "</mark>元，款项类型：" . $warranty_type . "：" . $value['part_name'] . "</p>";
                        }
                        break;
                }
            } elseif ($pay_info['type'] == 4) {
                $array = OrderGoodsModel::where(['pay_id' => $pay_id,'type'=>2])->select();
                foreach ($array as $key => &$value) {
                    $html .= "<p fid='1'>应交<mark >" . $value['total_price']. "</mark>元，款项类型：" . $value['goods_name'] . "：" . $value['goods_price']."*".$value['num'] . "</p>";
                }
                $danju_url = $danju_url."?type=11&pay_id={$pay_id}";
            }
            $this->assign([
                'pay_info' => $pay_info,
                'result' => $result,
                'receptionist' => cmf_get_admin_name($pay_info['handle']),
                'customer' => $result_customer,
                'deposit' => $result_deposit,
                'order_id' => $order_id,
                'html' => $html,
                'danju_url' => $danju_url,
                'menu'  => $menu
            ]);
            return $this->fetch('feil_details');
        }
    }

    public function feil_delf(){
        if ($this->request->isPost()){
            $pay_id = $this->request->param('pid');
            $pay_model = new OrderPayLogModel();
            $res = $pay_model->feil_delf($pay_id);
            if ($res){
                return $this->success('业务已取消，无法恢复，请重新提交相应的数据。','');
            }else{
                return $this->error($pay_model->getError());
            }
        }
    }

    public function ajax_print(){
        if ($this->request->isPost()){
            $type = $this->request->param('type');
            $itype = $this->request->param('itype',1);
            $result_data=[];
            $pay_id = $this->request->param('pid');
            $pay_info = OrderPayLogModel::where(['id' => $pay_id])->find();
            if ($type==1){
                $order_id = $this->request->param('oid');
                $mw_id = $this->request->param('mwid');
//              $mw_id = $this->request->param('mw_id');
                if ($itype==1){
                    $warranty = $this->request->param('warranty');
                    OrderModel::update(
                        [
                            'sj_create_time'=>time(),
                            'bxq_end_date'=>unixtime_to_date_inc(time(),intval($warranty)),
                            'is_jsdj'=>1
                        ],
                        [
                            'tomb_id'=>$mw_id,
                            'status'=>2,
                            'is_jsdj'=>0
                        ]);
                    $danju_url = url('Print/print_cert')."?type=2&&pay_id={$pay_id}";
                    $result_data['url'] = $danju_url;//unixtime_to_date_inc(time(),intval($warranty));
                }elseif ($itype==2){
                    $danju_url = url('Print/print_cert')."?type=2&pay_id={$pay_id}";
                    $result_data['url'] = $danju_url;
                }

            }elseif ($type== 2){
                $order_id = $this->request->param('oid');
                $mw_id = $this->request->param('mwid');
                $czr_id = $this->request->param('czrid');
                $tomb_number = $this->request->param('cno');
                if ($itype==1){
                    $mw_info = OrderModel::getOrderByid($order_id);
                    $info['add_time']= time();
                    $info['dz_create_time']= time();
                    $info['sj_create_time']= time();
                    $info['bxq_end_date']= unixtime_to_date_inc(time(),intval($mw_info['warranty']));
                    $dz['mz_dy_time'] = time();
                    $dz['is_dy_mz'] = 1;
                    $dz['tomb_number'] = $tomb_number;
                    CustomerInfoModel::update($dz,['id'=>$czr_id]);
                    OrderModel::update($info,['order_id'=>$order_id]);//墓证信息
                    $result_data = CustomerInfoModel::getmuzheng($czr_id);
                }elseif ($itype==2){
                    $mw_info = OrderModel::getOrderByid($order_id);
                    if ($mw_info['is_dy_mz']==0){
                        $info['add_time']= time();
                        $info['dz_create_time']= time();
                        $info['sj_create_time']= time();
                        $info['bxq_end_date']= unixtime_to_date_inc(time(),intval($mw_info['warranty']));
                        $dz['mz_dy_time'] = time();
                        $dz['is_dy_mz'] = 1;
                        $dz['tomb_number'] = $tomb_number;
                        OrderModel::update($info,['order_id'=>$order_id]);//墓证信息
                    }
                    $dz['is_dy_mz'] = 1;
                    $dz['tomb_number'] = $tomb_number;
                    CustomerInfoModel::update($dz,['id'=>$czr_id]);
                    $result_data = CustomerInfoModel::getmuzheng($czr_id);
                }
            }elseif ($type==3){
                $czr_id = $this->request->param('czrid');
                $result_data = CustomerInfoModel::getmuzheng($czr_id);
            }
            return $this->result($result_data);
        }
    }

    public function ajax_refund(){
        if ($this->request->isPost()) {
            $type = $this->request->param('type');
            $pid = $this->request->param('pid');
            $pay_model = new OrderPayLogModel();
            if ($type==1){
                $res = $pay_model->dorefundUpdataAndDelete($pid);
                if ($res){
                    $danju  = url('Print/print_cert')."?mark=3&type=1&refund_id={$pid}";
                    return $this->success('退款成功。墓位相关信息已清除，无法恢复。','',['danju'=>$danju]);
                }else{
                    return $this->error($pay_model->getError());
                }
            }elseif ($type==2){
                 $res = $pay_model->doRefreshUpdataDelete($pid);
                if ($res){
                    return $this->success('重置成功。相关信息已清除，无法恢复。');
                }else{
                    return $this->error($pay_model->getError());
                }
            }
        }
    }

    // 删除
    public function delete_pay($id){
        $msg = "";
        $code = 0;
        if(empty($id)){
            $msg = "没有找到该数据";
            $code = 1;
        }

        $p = Db::name('order_pay_log')->where(['id'=>$id])->find();
        if(empty($p)){
            $msg = "没有找到该数据";
            $code = 1;
        }else{
            $res = Db::name('order_pay_log')->where(['id'=>$id])->update(['is_delete'=>1]);
            if(!$res){

                $msg = "删除失败";
                $code = 1;
            }else{
                $msg = "删除成功";
            }
        }
        return json(['code'=>$code,'msg'=>$msg]);
    }

    public function getContract(){
        $id = $this->request->param("id");
        $data = Db::name("purchase")->alias("p")
            ->field("p.*,u.user_nickname")
            ->join("dj_user u","u.id = p.add_user","left")
            ->where('purchase_id',$id)->find();
        if($data){
            $data['add_time'] = date('Y-m-d',$data['add_time']);
            $data['due_time'] = date('Y-m-d',$data['due_time']);
        }
        exit(json_encode($data));
    }


    /**-----------------打印内容--------------------------------------------------------------------------------------*/

    //落葬 结算单
    public  function getBuriedInfo($customer_id,$id){
        $service_info = ServiceBuriedModel::where(['id'=>$id])->find();
        $result_project = Db::name('pay_project')->where(['buried_id'=>$id])->select();
        $array_top = $this->getTopInfo($customer_id);
        $array_top['handle_name'] = $service_info['handle_name'];
        $array_top['pay_name'] = '';
        $array_top['time'] = unixtime_to_date($service_info['add_time'],'Y.m.d');

        $tr_html='';
        for ($i=count($result_project)+2;$i<9;$i++){
            $tr_html.=' <tr><td colspan="8"></td></tr>';
        }
        $array_top['result_list'] = $result_project;
        $array_top['html_tr'] = $tr_html;
        return $array_top;
    }

    //共同的头部尾部信息
    public  function  getTopInfo($customer_id)
    {
        $OrderModel = new OrderModel();
        $result_info = $OrderModel->getRefundOrderBy($customer_id,0);
        $array_top['buyer_name'] = $result_info['buyer_name'];
        $array_top['buyer_phone'] = $result_info['buyer_phone'];
        $array_top['cart_type'] = cart_type('cart',$result_info['cart_type']);
        $array_top['customer_account'] = $result_info['customer_account'];
        $array_top['customer_address'] = $result_info['customer_address'];
        $array_top['contract_sn'] = $result_info['contract_sn'];
        $array_top['tomb_num'] = $result_info['tomb_num'];
        $array_top['tomb_region'] = $result_info['tomb_region'].$result_info['tomb_address'].$result_info['tomb_bit_number'];
        $array_top['tomb_regulation_name'] = $result_info['tomb_regulation_name'];
        $array_top['status_name'] = $result_info['col_status_name'];
        return $array_top;
    }

}